package com.baosight.sczx.common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.sczx.common.zm.basetools.StaticTools;

public class StaticBlocks {

	/**
	 * 
	 * <p>Function: getBlockData</p>
	 * <p>Description: 构造Block的的下拉框数据</p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年10月13日上午9:46:04 郭淑芳
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public static EiBlock getBlockData(String blockName, String[] args, boolean isAll) {
		EiBlock block = new EiBlock(blockName);

		EiColumn EiColumn = new EiColumn("display");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		EiColumn = new EiColumn("value");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		List<Map> _list = new ArrayList<Map>();
		Map<String, String> _map;

		if (isAll) {
			_map = new HashMap<String, String>();
			_map.put("value", "");
			_map.put("display", "");
			_list.add(_map);
		}

		for (int i = 0; i < args.length; i++) {
			_map = new HashMap<String, String>();
			_map.put("value", String.valueOf(i));
			_map.put("display", args[i]);
			_list.add(_map);
		}

		block.setRows(_list);
		return block;
	}

	/**
	 * 
	 * <p>Function: getBlockData</p>
	 * <p>Description: 构造Block的的下拉框数据</p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年10月13日上午9:46:23 郭淑芳
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public static EiBlock getBlockData(String blockName, String[] valueArgs, String[] displayArgs, boolean isAll) {
		EiBlock block = new EiBlock(blockName);

		EiColumn EiColumn = new EiColumn("display");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		EiColumn = new EiColumn("value");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		List<Map> _list = new ArrayList<Map>();
		Map<String, String> _map;

		if (isAll) {
			_map = new HashMap<String, String>();
			_map.put("value", "");
			_map.put("display", "");
			_list.add(_map);
		}

		for (int i = 0; i < valueArgs.length; i++) {
			_map = new HashMap<String, String>();
			_map.put("value", valueArgs[i]);
			_map.put("display", displayArgs[i] == null ? "" : displayArgs[i]);
			_list.add(_map);
		}

		block.setRows(_list);
		return block;
	}

	/// <summary>
	/// 计划月份
	/// </summary>
	/// <returns></returns>
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static EiBlock getPlanMonth(String blockName, boolean isAll) {
		EiBlock block = new EiBlock(blockName);

		EiColumn EiColumn = new EiColumn("display");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		EiColumn = new EiColumn("value");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		List<Map> _list = new ArrayList<Map>();
		Map _map = null;

		if (isAll) {
			_map = new HashMap<String, String>();
			_map.put("value", "");
			_map.put("display", "");
			_list.add(_map);
		}

		for (int i = 0; i < 12; i++) {
			_map = new HashMap<String, String>();
			_map.put("value", i < 9 ? "0" + (i + 1) : (i + 1) + "");
			_map.put("display", i < 9 ? "0" + (i + 1) : (i + 1) + "");
			_list.add(_map);
		}

		block.setRows(_list);
		return block;
	}

	/// <summary>
	/// 计划状态
	/// </summary>
	/// <returns></returns>
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static EiBlock getPlanStatus(String blockName, boolean isAll) {
		EiBlock block = new EiBlock(blockName);

		EiColumn EiColumn = new EiColumn("display");
		EiColumn.setType("C");
		block.addMeta(EiColumn);
		EiColumn = new EiColumn("value");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		List<Map> _list = new ArrayList<Map>();
		Map _map = null;

		if (isAll) {
			_map = new HashMap<String, String>();
			_map.put("value", "");
			_map.put("display", "");
			_list.add(_map);
		}

		_map = new HashMap<String, String>();
		_map.put("value", "草拟");
		_map.put("display", "草拟");
		_list.add(_map);

		_map = new HashMap<String, String>();
		_map.put("value", "上报");
		_map.put("display", "上报");
		_list.add(_map);

		_map = new HashMap<String, String>();
		_map.put("value", "作废");
		_map.put("display", "作废");
		_list.add(_map);

		_map = new HashMap<String, String>();
		_map.put("value", "历史");
		_map.put("display", "历史");
		_list.add(_map);

		block.setRows(_list);
		return block;
	}

	/**
	 * 得到年份下拉框（从当前年开始），例如传入3，得到：2016/2015/2014 返回block名字为：cmes.cs.year
	 * 
	 * @param int
	 *            需要得到的年份数
	 */
	public static EiBlock getYearBlock(int count) {
		EiBlock block = new EiBlock("cmes.cs.year");

		EiColumn EiColumn = new EiColumn("display");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		EiColumn = new EiColumn("value");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		String year = StaticTools.getYear();
		@SuppressWarnings("rawtypes")
		List<Map> _list = new ArrayList<Map>();
		for (int i = 0; i < count; i++) {
			Map<String, String> _map = new HashMap<String, String>();
			_map.put("display", (Integer.parseInt(year) - i) + "");
			_map.put("value", (Integer.parseInt(year) - i) + "");
			_list.add(_map);
		}
		block.addRows(_list);
		return block;
	}

	/**
	 * 得到月份下拉框（根据参数前台显示汉字或数字，后台传回数字） 返回block名字为：cmes.cs.month
	 * 
	 * @param type
	 *            int：1：前台显示汉字，0：前台显示数字
	 * @param type
	 *            bool:true:加空选项，false：不见空选项
	 */
	public static EiBlock getMonthBlock(int type, boolean isAll) {
		EiBlock block = new EiBlock("cmes.cs.month");

		EiColumn EiColumn = new EiColumn("display");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		EiColumn = new EiColumn("value");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		@SuppressWarnings("rawtypes")
		List<Map> _list = new ArrayList<Map>();
		if (isAll) {
			Map<String, String> _map = new HashMap<String, String>();
			_map.put("display", "");
			_map.put("value", "");
			_list.add(_map);
		}
		for (int i = 1; i < 13; i++) {
			Map<String, String> _map = new HashMap<String, String>();
			if (type == 1) {
				_map.put("display", StaticTools.getCMonth(i + ""));
			} else {
				if (i < 10) {
					_map.put("display", "0" + i);
				} else {
					_map.put("display", "" + i);
				}
			}
			if (i < 10) {
				_map.put("value", "0" + i);
			} else {
				_map.put("value", "" + i);
			}
			_list.add(_map);
		}
		block.addRows(_list);
		return block;
	}
}
